package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 服务器返回查询装备详情消息
 */
public class Goods_SearchEquipDetailReturnProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 16007; }

    public Integer EnchantLevel; //强化等级
    public byte BaseAttr1Type; //基础属性1类型
    public Integer BaseAttr1Value; //基础属性1值
    public byte BaseAttr2Type; //基础属性2类型
    public Integer BaseAttr2Value; //基础属性2值
    public Integer HP; //生命
    public Integer MP; //魔法
    public Integer Attack; //攻击
    public Integer Defense; //防御
    public Integer Hit; //命中
    public Integer Dodge; //闪避
    public Integer Cri; //暴击
    public Integer Res; //抗性
    public byte IsPutOn; //是否穿戴

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteInt(EnchantLevel);
            dataStream.WriteByte(BaseAttr1Type);
            dataStream.WriteInt(BaseAttr1Value);
            dataStream.WriteByte(BaseAttr2Type);
            dataStream.WriteInt(BaseAttr2Value);
            dataStream.WriteInt(HP);
            dataStream.WriteInt(MP);
            dataStream.WriteInt(Attack);
            dataStream.WriteInt(Defense);
            dataStream.WriteInt(Hit);
            dataStream.WriteInt(Dodge);
            dataStream.WriteInt(Cri);
            dataStream.WriteInt(Res);
            dataStream.WriteByte(IsPutOn);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static Goods_SearchEquipDetailReturnProto GetProto(byte[] buffer) {
        Goods_SearchEquipDetailReturnProto proto = new Goods_SearchEquipDetailReturnProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.EnchantLevel = dataStream.ReadInt();
            proto.BaseAttr1Type = (byte)dataStream.ReadByte();
            proto.BaseAttr1Value = dataStream.ReadInt();
            proto.BaseAttr2Type = (byte)dataStream.ReadByte();
            proto.BaseAttr2Value = dataStream.ReadInt();
            proto.HP = dataStream.ReadInt();
            proto.MP = dataStream.ReadInt();
            proto.Attack = dataStream.ReadInt();
            proto.Defense = dataStream.ReadInt();
            proto.Hit = dataStream.ReadInt();
            proto.Dodge = dataStream.ReadInt();
            proto.Cri = dataStream.ReadInt();
            proto.Res = dataStream.ReadInt();
            proto.IsPutOn = (byte)dataStream.ReadByte();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}